package com.dayuanit.pay.bank.handler;

import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dayuanit.pay.domain.PayOrder;

/**
 * 处理银行支付
 * 
 */
public abstract class PayBaseHandler {
	
	protected final static Logger log = LoggerFactory.getLogger(PayBaseHandler.class);
	
	/**
	 * 获取第三方支付网管的地址
	 * @return
	 */
	protected abstract String getOrderPayUrl();
	
	/**
	 * 获取第三方支付查询地址
	 * @return
	 */
	protected abstract String getOrderQueryPayUrl();
	
	/**
	 * 获取第三方请求参数
	 * @return
	 */
	protected abstract Map<String, Object> getOrderPayParam(PayOrder payOrder);
	
	/**
	 * 创建第三方系统支付的请求参数 以form表单的形式提交
	 */
	public String createOrderPayParam(PayOrder payOrder) {
		
		//拼装Form表单
		String form = "<form id=\"payForm\" action=\"" + getOrderPayUrl() + "\" method=\"post\">";
		Map<String, Object> payParam = getOrderPayParam(payOrder);
		Set<Map.Entry<String, Object>> set = payParam.entrySet();
		for (Map.Entry<String, Object> entry : set) {
			form += "<input type=\"text\" name=\"" + entry.getKey() + "\" value=\"" + entry.getValue() + "\">";
		}
		
		form += "</form>";
		
		log.info("订单Form信息：{}", form);
		return form;
	}
	
	/**
	 * 请求第三方系统查询订单状态 防止掉单
	 */
	public boolean orderSearch(PayOrder payOrder) throws Exception {
		return false;
	}
	
}
